package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.HeaderPresenter;
import com.emser.unc.client.resources.GlobalResources;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class HeaderView extends Composite implements HeaderPresenter.Display {	
	private Label userName;
	private Button btnLogout;
	private final GlobalResources resource;
	
	public HeaderView() {
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setStyleName("gwt-HorizontalPanelH");
		initWidget(horizontalPanel);
		horizontalPanel.setSize("100%", "100%");
		resource = GWT.create(GlobalResources.class);
		Image image = new Image(resource.getICloud());
		horizontalPanel.add(image);
		image.setSize("190", "87");
		
		VerticalPanel verticalPanel = new VerticalPanel();
		verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		verticalPanel.setStyleName("gwt-VPanelH");
		horizontalPanel.add(verticalPanel);
		horizontalPanel.setCellVerticalAlignment(verticalPanel, HasVerticalAlignment.ALIGN_MIDDLE);
		horizontalPanel.setCellHorizontalAlignment(verticalPanel, HasHorizontalAlignment.ALIGN_RIGHT);
		horizontalPanel.setCellWidth(verticalPanel, "400px");
		verticalPanel.setSize("400px", "77px");
		horizontalPanel.setCellHeight(verticalPanel, "77px");
		
		btnLogout = new Button(CloudMobile.constants.logout());
		verticalPanel.add(btnLogout);
		btnLogout.setSize("73", "24");
		verticalPanel.setCellHorizontalAlignment(btnLogout, HasHorizontalAlignment.ALIGN_RIGHT);
		
		userName = new Label(CloudMobile.constants.userNameDefault());
		userName.setStyleName("Label-Logout");
		userName.setStylePrimaryName("Label-Logout");
		userName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		verticalPanel.add(userName);
		userName.setSize("250px", "20px");
		verticalPanel.setCellWidth(userName, "250px");
		verticalPanel.setCellHeight(userName, "20px");
		verticalPanel.setCellHorizontalAlignment(userName, HasHorizontalAlignment.ALIGN_RIGHT);
		verticalPanel.setCellVerticalAlignment(userName, HasVerticalAlignment.ALIGN_BOTTOM);
		
	}
	
	@Override
	public Widget asWidget() {
	    return this;
	}

	@Override
	public HasClickHandlers getLogoutButton() {
		return btnLogout;
	}

	@Override
	public HasText getUserNameLabel() {
		return userName;
	}

}
